package com.ziven.common.widget.value;

import android.view.View;

import androidx.annotation.NonNull;

import com.ziven.easygo.util.EasyUtils;
import com.ziven.easygo.util.ViewHelper;

/**
 * @author Ziven
 */
public final class TakeEffect extends MixValue {

    public static TakeEffect values(@NonNull Value... values) {
        return new TakeEffect(values);
    }

    private TakeEffect(@NonNull Value... values) {
        super(values);
    }

    @Override
    protected void takeEffect(@NonNull ViewHelper<? extends View> helper, @NonNull Value[] values) {
        if(viewId == View.NO_ID) {
            EasyUtils.forEach(values, value -> value.takeEffect(helper.getView()));
        } else {
            helper.getViewNulls().doNotNull(view -> {
                View child = view.findViewById(viewId);
                EasyUtils.forEach(values, value -> value.takeEffect(child));
            });
        }
    }
}
